<?php

class ImExportPlugin {
	var $ld;
	var $xmlsOb;
	var $bot;

	function ImExportPlugin() {
		$this->ld = new LocalData();
	    $this->xmlsOb = new xmlsOb();
		$bot = new Bot();
	}
	// ==========================================================================
	function GetOptionsByTypeName($name)
	{   global $imagePath;
		$res=""; //"<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name)
			{
				if($name == "train")
				{
					if(substr_count($item['name'],"schedule") > 0) $res=$res.'<option value="'.$item['name'].'" >'.$item['name']."</option>";
				}
				else
				{
					$res=$res."<option>".(string)$item['name']."</option>";
				}
			}
		}
		return $res;
	}
	// ==========================================================================
	function GetContractByTypeAndKeyword($name, $keyword)
	{  global $imagePath;
		$res=""; //"<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name)
			{
				if((string)$item->keyword [1] == $keyword)
				$res=$res."<option>".(string)$item['name']."</option>";
			}
		}
		return $res;
	}
    // ==========================================================================
	function GetTruckingContractByGoods($name)
	{  global $imagePath;
		$res=""; //"<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name)
			{
				if((string)$item->goods)
				$res=$res."<option>".(string)$item['name']."</option>";
			}
		}
		return $res;
	}
	// ==========================================================================
	function GetShips()
	{
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td></td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if($obj['className'] == "Ship")

			{
				if((string)$obj['state'] == "grown") { $state = "Ready";}
				else
				if((string)$obj['state'] == "plowed") { $state = "Harbored";}
				else{ $state = "Underway";}
				//  String  rio   Number  1292943824000                                                                                     String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['contractName']."</td><td>".$this->ld->nicetime($obj['plantTime']/1000)."</td><td>Returns</td><td>".$state."</td><td></td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;

	}
	// ==========================================================================
	function GetShips1()
	{
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td></td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if($obj['className'] == "HarvestableShip")

			{
				if((string)$obj['state'] == "grown") { $state = "Ready";}
				else
				if((string)$obj['state'] == "plowed") { $state = "Harbored";}
				else{ $state = "Underway";}
				//  String  rio   Number  1292943824000                                                                                     String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['contractName']."</td><td>".$this->ld->nicetime($obj['plantTime']/1000)."</td><td>Returns</td><td>".$state."</td><td></td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;

	}	
	// ==========================================================================
	function GetTrucks()
	{
	$artruckContracts = array(		   
	"trucking_frankfurt" => 1 * 60, //1mins
	"trucking_losangeles" => 1 * 60 * 60, //1 hours
	"trucking_zurich" => 4 * 60 * 60, //4 hours
	"trucking_atlanta" => 8 * 60 * 60, //8 hours
	"trucking_barcelona" => 12 * 60 * 60, //12 hours
	"trucking_chicago" => 16 * 60 * 60, //16 hours
	"trucking_boston" => 24 * 60 * 60 //24 hours		   
	);
		
		$witheredError = 3; //The amount of extra time the server will give to a crop before it withers
		
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name</td><td>ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td>Time</td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from dt_objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if($obj['className'] == "Truck")

			{
				$contract = $obj["mechanicData"]["contract"]["contractName"];
				$contractStarted = $obj["mechanicData"]["contract"]["plantTime"];
				
				if((string)$obj['state'] == "plowed") {
					$state = "empty";
					$time = "-";
				}
				else{
					if((string)$obj["state"] == "planted"){
						$timeReady = $contractStarted + $artruckContracts[$contract];
						$timeWithered = $contractStarted + $witheredError*$artruckContracts[$contract];					
						
						if($timeReady > time()) {
							$state = "underway";
							$time = "will be ready in ".$this->ld->nicetime($timeReady);
						}
						else{
							if ($contract != "trucking_frankfurt"){
								if ($timeWithered > time()){
									$state = "ready";
									$time = "will be withered in ".$this->ld->nicetime($timeWithered)." (".date('H:i:s d M Y', $timeWithered).")";
								}
								else{
									$state = "whitered";
									$time = "-";
								}
							}
							else{
								$state = "ready";
								$time = "-";
							}
						}
					}
				}
				//  String  rio   Number  1292943824000                                                                                     String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']."</td><td>".$obj['id']."</td><td>".$obj['mechanicData']['contract']['contractName']."</td><td>".$this->ld->nicetime($obj['mechanicData']['contract']['plantTime'])."</td><td>Returns</td><td> ".$state." </td><td>".$time."</td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;
	}	
	// ==========================================================================		
	function GetPlanesCargo()
	{
		$arcargoContracts = array(
		"paris_plane" => 5 * 60, //5mins
		"barcelona_plane" => 6 * 60 * 60, //6 hours
		"shanghai_plane" => 12 * 60 * 60, //12 hours
		"tokyo_plane" => 18 * 60 * 60, //18 hours
		"london_plane" => 24 * 60 * 60 //24 hours
		);
		
		$witheredError = 3; //The amount of extra time the server will give to a crop before it withers
		
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td>Time</td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if (((string)$obj['itemName'] == "sky_cargo_plane") ||
					((string)$obj['itemName'] == "cloud_cargo_plane") ||
					((string)$obj['itemName'] == "air_cargo_plane"))

			{
				$contract = $obj["mechanicData"]["contract"]["contractName"];
				$contractStarted = $obj["mechanicData"]["contract"]["plantTime"];
				
				if((string)$obj['state'] == "plowed") {
					$state = "empty";
					$time = "-";
				}
				else{
					if((string)$obj["state"] == "planted"){
						$timeReady = $contractStarted + $arcargoContracts[$contract];
						$timeWithered = $contractStarted + $witheredError*$arcargoContracts[$contract];					
						
						if($timeReady > time()) {
							$state = "underway";
							$time = "will be ready in ".$this->ld->nicetime($timeReady);
						}
						else{
							if ($contract != "paris_plane"){
								if ($timeWithered > time()){
									$state = "ready";
									$time = "will be withered in ".$this->ld->nicetime($timeWithered)." (".date('H:i:s d M Y', $timeWithered).")";
								}
								else{
									$state = "whitered";
									$time = "-";
								}
							}
							else{
								$state = "ready";
								$time = "-";
							}
						}
					}
				}
				//  String  rio   Number  1292943824000                                                                                     String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['mechanicData']['contract']['contractName']."</td><td>".$this->ld->nicetime($obj['mechanicData']['contract']['plantTime'])."</td><td>Returns</td><td> ".$state." </td><td>".$time."</td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;
	}
	// ==========================================================================
	function GetPlanesPassenger()
	{
		$arpassengerContracts = array(		   
	    "rome_plane" => 1 * 60, //1mins
	    "toronto_plane" => 1 * 60 * 60, //1 hours
	    "new_york_plane" => 6 * 60 * 60, //6 hours
	    "berlin_plane" => 8 * 60 * 60, //8 hours
	     "rio_plane" => 12 * 60 * 60 //12 hours		   
	);
	
	
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td>Time</td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if(((string)$obj['itemName'] == "cityville_passenger_plane") ||
					((string)$obj['itemName'] == "econair_passenger_plane") ||
					((string)$obj['itemName'] == "jetset_passenger_plane") ||
					((string)$obj['itemName'] == "firstclass_passenger_plane") ||
					((string)$obj['itemName'] == "privatejet_passenger_plane"))

			{
				$contract = $obj["mechanicData"]["contract"]["contractName"];
				$contractStarted = $obj["mechanicData"]["contract"]["plantTime"];
				
				if((string)$obj['state'] == "plowed") {
					$state = "empty";
					$time = "-";
				}
				else{
					if((string)$obj["state"] == "planted"){
						$timeReady = $contractStarted + $arpassengerContracts[$contract];				
						
						if($timeReady > time()) {
							$state = "underway";
							$time = "will be ready in ".$this->ld->nicetime($timeReady);
						}
						else{
							$state = "ready";
							$time = "-";
						}
					}
				}
				//  String  rio   Number  1292943824000 String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['mechanicData']['contract']['contractName']."</td><td>".$this->ld->nicetime($obj['mechanicData']['contract']['plantTime'])."</td><td>Returns</td><td> ".$state." </td><td>".$time."</td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;
	}
	// ==========================================================================
	function GetPlanesHoliday()
	{
		$arvacationContracts = array(		   
		"cairo_plane" => 1 * 60 * 60, //1 hours
		"mumbai_plane" => 18 * 60 * 60, //18 hours
		"seoul_plane" => 24 * 60 * 60 //24 hours		   
		);
		
		
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td>Time</td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if  ((string)$obj['itemName'] == "dreamline_plane")

			{
				$contract = $obj["mechanicData"]["contract"]["contractName"];
				$contractStarted = $obj["mechanicData"]["contract"]["plantTime"];
				
				if((string)$obj['state'] == "plowed") {
					$state = "empty";
					$time = "-";
				}
				else{
					if((string)$obj["state"] == "planted"){
						$timeReady = $contractStarted + $arvacationContracts[$contract];				
						
						if($timeReady > time()) {
							$state = "underway";
							$time = "will be ready in ".$this->ld->nicetime($timeReady);
						}
						else{
							$state = "ready";
							$time = "-";
						}
					}
				}
				//  String  rio   Number  1292943824000 String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['mechanicData']['contract']['contractName']."</td><td>".$this->ld->nicetime($obj['mechanicData']['contract']['plantTime'])."</td><td>Returns</td><td> ".$state." </td><td>".$time."</td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;
	}
	// ==========================================================================
	function GetPlanesPrivate()
	{
		$arvacationContracts = array(		   
		"washington_plane" => 4 * 60 * 60, //4 hours
		"buenos_plane" => 4 * 60 * 60, //4 hours
		"geneva_plane" => 4 * 60 * 60, //4 hours	
		"cannes_plane" => 4 * 60 * 60, //4 hours
		"hongkong_plane" => 4 * 60 * 60 //4 hours
		);
		
		
		$ret = '<table class="table1">';
		$ret .= "<tr><td>Name / ID</td><td>Route</td><td>Started</td><td>Returns</td><td>State</td><td>Time</td><td></td></tr>";
		$res=$this->ld->GetSelect("select * from objects");
		foreach ($res as $val){
			$v=(string)$val[1];
			$obj=unserialize(base64_decode($v));
			if (((string)$obj['itemName'] == "skywing_jet") ||
			    ((string)$obj['itemName'] == "time_pigeon_jet"))

			{
				$contract = $obj["mechanicData"]["contract"]["contractName"];
				$contractStarted = $obj["mechanicData"]["contract"]["plantTime"];
				
				if((string)$obj['state'] == "plowed") {
					$state = "empty";
					$time = "-";
				}
				else{
					if((string)$obj["state"] == "planted"){
						$timeReady = $contractStarted + $arvacationContracts[$contract];				
						
						if($timeReady > time()) {
							$state = "underway";
							$time = "will be ready in ".$this->ld->nicetime($timeReady);
						}
						else{
							$state = "ready";
							$time = "-";
						}
					}
				}
				//  String  rio   Number  1292943824000 String Reference  grown
				$ret .= "<tr><td>".$obj['itemName']." / ".$obj['id']."</td><td>".$obj['mechanicData']['contract']['contractName']."</td><td>".$this->ld->nicetime($obj['mechanicData']['contract']['plantTime'])."</td><td>Returns</td><td> ".$state." </td><td>".$time."</td><td></td></tr>";

			}
		}
		$ret .= "</table>";
		return $ret;
	}
	// ==========================================================================
	function GetOptionsByTypeName2($name)
	{
		$res=""; //"<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name){
				$totCoins = $item->trainBuyPrice * $item->trainStorage ;
				$notUse = "&nbsp;";
				if($item['name'] == "train") { $notUse = "DO NOT USE THIS.";}
				if($item['name'] == "handcar_train") { $notUse = "DO NOT USE THIS.";}
				if($item['name'] == "bullet_train") { $notUse = "DO NOT USE THIS.";}
				$res=$res."<tr><td>".(string)$item['name']. " </td><td> " . (string)$item->trainTripTime ." Sec </td><td> " . (string)$item->trainStorage ." Goods </td><td> " . (string)$item->trainBuyPrice ." Coins </td><td> Total: " . $totCoins . " Coins</td><td>".(string)$item->requiredQuestFlag." ". $notUse."</td></tr>";
			}
		}
		return $res;
	}

	// ==========================================================================
	function GetXMLtime($time)
	{
		$tmptime = (string)$time*(23/24); // now the time is in days.
		$tmptime = $tmptime * 24 * 60 ; // now time is in min.
		if($tmptime >= 0 && $tmptime < 60){ $tmptime= round($tmptime, 1)." Min."; }
		if($tmptime >= 60 && $tmptime < 3600){ $tmptime= round($tmptime/60, 1)." Hour"; }
		if($tmptime >= 3660 && $tmptime < 86400){ $tmptime= round($tmptime/60/24, 1)." Day"; }
		$nicetime = $tmptime;
		return $nicetime;
	}
	// ==========================================================================
	function GetOptionsShip($name)
	{
		$Table = array();
		foreach ($this->xmlsOb->gsXML->randomModifierTables->randomModifierTable as $tmp)
		{
			//echo "type ".  $tmp['type'] ."  \n";
			//$Table[$tmp['name']]['type']   = $tmp['type'];
			//$Table[$tmp['name']]['amount'] = $tmp->roll->goods ;
		}
		//var_dump($Table);
		$res=""; //"<option>any</option>";
		foreach ($this->xmlsOb->gsXML->items->item as $item) {
			if ((string)$item['type'] == $name){
				$totCoins = $item->trainBuyPrice * $item->trainStorage ;
				$notUse = "&nbsp;";

				foreach($item->randomModifiers as $modifier )
				{
					if($modifier->modifier['type'] == "goods") {$TableName = $modifier->modifier['tableName'];}
				}
				$tmpamount = "Unknown";
				foreach ($this->xmlsOb->gsXML->randomModifierTables->randomModifierTable as $tmp)
				{
					//echo $tmp['name'] . "<br>\n";
					if($tmp['name'] == (string)$TableName) {  $tmpamount = $tmp->roll->goods['amount'];}
				}
				$amountOfGoods = $tmpamount;
				$time = $this->GetXMLtime($item->growTime);
				$CoinsPgood = round((string)$item->cost / $amountOfGoods, 2);
				$res=$res."<tr><td>".(string)$item['name']. " </td><td>" .$time." </td><td> " . $amountOfGoods ." Goods </td><td> " . $CoinsPgood ." Coins </td><td> Total: " . (string)$item->cost . " Coins</td><td>".(string)$item->requiredQuestFlag." </td></tr>";
			}
		}
		return $res;
	}
	// ==========================================================================
	function GetForm()
	{
		global $imagePath;
		$imagePath = substr($_SERVER["PHP_SELF"], 0, strpos($_SERVER["PHP_SELF"], "/"));
		$PlVersion = (array)$this->ld->GetPlVersion('im-export');
		$settings = (array) $this->ld->GetPlSettings('im-export');


		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml" lang="ru">
		<head>
		<title>ImExport</title>
		<script src="..\..\codebase-php\jquery-1.4.2.min.js"></script>
		<script src="..\..\codebase-php\jquery.json-2.2.min.js"></script>
		<link href="helpers/plugin.css" rel="stylesheet" type="text/css">
		<style>
			#maint{ font-size: 10pt; width: 850px; padding: 0px; }
		</style>

		<script language="JavaScript" type="text/javascript">
		<!--
		var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
		function addOption(theSel, theText, theValue)
		{
			var newOpt = new Option(theText, theValue);
			var selLength = theSel.length;
			theSel.options[selLength] = newOpt;
		}

		function deleteOption(theSel, theIndex)
		{
			var selLength = theSel.length;
			if(selLength>0)
			{
			theSel.options[theIndex] = null;
			}
		}

		function moveOptions(theSelFrom, theSelTo)
		{
			var selLength = theSelFrom.length;
			var selectedText = new Array();
			var selectedValues = new Array();
			var selectedCount = 0;
			var i;
			// Find the selected Options in reverse order and delete them from the from Select.
			for(i=selLength-1; i>=0; i--)
			{
			if(theSelFrom.options[i].selected)
			{
				selectedText[selectedCount] = theSelFrom.options[i].text;
				selectedValues[selectedCount] = theSelFrom.options[i].value;
				deleteOption(theSelFrom, i);
				selectedCount++;
			}
			}

			// Add the selected text/values in reverse order.
			// This will add the Options to the TO Select
			// in the same order as they were in the FROM Select.
			for(i=selectedCount-1; i>=0; i--)
			{
			addOption(theSelTo, selectedText[i], selectedValues[i]);
			}

			if(NS4) history.go(0);
		}
		//-->
		</script>


		<script language="javascript">
		<!-- For select images box
		function showimage() { if (!document.images) return
			document.images.pictures.src=document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value }
		//-->
		</script>

		<script>
		function sortSelect(selElem) {
				var tmpAry = new Array();
				for (var i=0;i<selElem.options.length;i++) {
						tmpAry[i] = new Array();
						tmpAry[i][0] = selElem.options[i].text;
						tmpAry[i][1] = selElem.options[i].value;
				}
				tmpAry.sort();
				while (selElem.options.length > 0) {
					selElem.options[0] = null;
				}
				for (var i=0;i<tmpAry.length;i++) {
						var op = new Option(tmpAry[i][0], tmpAry[i][1]);
						selElem.options[i] = op;
				}
				return;
		}

		//==============================================================
		window.reload = function(){
			var l=window.location.toString();
			var indx=l.indexOf(\'?\');
			window.location=l.slice(0, indx)+"?action=refresh&tmp="+Math.random();
		}
		//==============================================================
		$(document).ready(
			function()
			{
			window.settings=eval(' . json_encode($this->ld->GetPlSettings('im-export')) . ');
			if ((window.settings!==null) && (window.settings!==undefined))
			{
				$("#trainMissionIN").val(window.settings.trainMissionIN);
				$("#shipMissionIN").val(window.settings.shipMissionIN);
				$("#cruiseMissionIN").val(window.settings.cruiseMissionIN);
				$("#truckingContractIN").val(window.settings.truckingContractIN);
				$("#airplaneMissionCargoIN").val(window.settings.airplaneMissionCargoIN);
				$("#airplaneMissionPassengerIN").val(window.settings.airplaneMissionPassengerIN);
				$("#airplaneMissionVacationIN").val(window.settings.airplaneMissionVacationIN);
				$("#airplaneMissionPrivateIN").val(window.settings.airplaneMissionPrivateIN);
				
				$(":checkbox").each(
					function(){
					if(window.settings[$(this).attr("id")]==true){
						$(this).attr("checked", true);
					}
					else{
						$(this).attr("checked", false);
					}
					});
				$(":radio").each(
					function(){
					if(window.settings[$(this).attr("id")]==true){
						$(this).attr("checked", true);
					}
					else{
						$(this).attr("checked", false);
					}
					});
				$(":text").each(
					function (){
					var attr=$(this).attr("id");
					if (window.settings[attr]!==null){
						$(this).val(window.settings[attr]);
					}
					else{
						$(this).val("0");
					}
					});
			}
			//==============================================================
			$("#btn_save").click(
				function(){
					var req=new Object();
					$(":checkbox").each(
					function(){
						var par=$(this).attr("id");
						req[par]=$(this).attr("checked");
						if (($(this).attr("objid")!==null) && ($(this).attr("objid")!==undefined))
						{
						req[par+"ID"]=$(this).attr("objid");
						}
					});
					$(":radio").each(
					function(){
						var par=$(this).attr("id");
						req[par]=$(this).attr("checked");
						if (($(this).attr("objid")!==null) && ($(this).attr("objid")!==undefined))
						{
						req[par+"ID"]=$(this).attr("objid");
						}
					});
					$("input:text").each(function()
					{
					req[$(this).attr("id")]=$(this).val();
					});

					req["trainMissionIN"]=$("#trainMissionIN").val();
					//req["shipMissionIN"]=$("#shipMissionIN  :selected").text();
						req["shipMissionIN"]=$("#shipMissionIN").val();
						req["cruiseMissionIN"]=$("#cruiseMissionIN").val();
						req["truckingContractIN"]=$("#truckingContractIN").val();
						req["airplaneMissionCargoIN"]=$("#airplaneMissionCargoIN").val();
						req["airplaneMissionPassengerIN"]=$("#airplaneMissionPassengerIN").val();
						req["airplaneMissionVacationIN"]=$("#airplaneMissionVacationIN").val();
						req["airplaneMissionPrivateIN"]=$("#airplaneMissionPrivateIN").val();
	
					req.collectCruiseIN=new Array();
					$("#collectCruiseIN option").each(
					function(){
						var par=$(this).val();
						req.collectCruiseIN.push(par);
						//req.collectCruiseIN.push($(this).attr("id")+""+$(this).text());
					});
					
					req.collectTruckIN=new Array();
					$("#collectTruckIN option").each(
					function(){
						var par=$(this).val();
						req.collectTruckIN.push(par);
						//req.collectTruckIN.push($(this).attr("id")+""+$(this).text());
					});
					
					req.collectCargoIN=new Array();
					$("#collectCargoIN option").each(
					function(){
						var par=$(this).val();
						req.collectCargoIN.push(par);
						//req.collectCargoIN.push($(this).attr("id")+""+$(this).text());
					});
					
					req.collectPassengerIN=new Array();
					$("#collectPassengerIN option").each(
					function(){
						var par=$(this).val();
						req.collectPassengerIN.push(par);
						//req.collectPassengerIN.push($(this).attr("id")+""+$(this).text());
					});
					
					req.collectVacationIN=new Array();
					$("#collectVacationIN option").each(
					function(){
						var par=$(this).val();
						req.collectVacationIN.push(par);
						//req.collectVacationIN.push($(this).attr("id")+""+$(this).text());
					});
					
				    req.collectPrivateIN=new Array();
					$("#collectPrivateIN option").each(
					function(){
						var par=$(this).val();
						req.collectPrivateIN.push(par);
						//req.collectPrivateIN.push($(this).attr("id")+""+$(this).text());
					});

					data=$.toJSON(req);
					var l=window.location.toString();
					var indx=l.indexOf(\'?\');
					var nurl=l.slice(0, indx)+"?action=save&tmp="+Math.random();
					$.post(nurl, data);

					return false;
			});
			});
		</script>

		</head>
		<body>
			<form name="mygallery">';

		echo  '<table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#DAA520">
			<tr height="23">
			<td><hr><h1>CV Im-Export v0.7</h1>
			<h5>Updated by BQ (11.05.2012)</h5><hr></td>
			</tr>
			</table>
			<br>
			</div>  
		<b>Options</b>:
			<br>
			<input type="checkbox" id="ALLbonus">Streak Bonus for Ships & Planes<br>
			<br>';
		// Trains ================================================================================			
		echo  '<table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Trains</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<td>
				<input type="checkbox" id="NoTrainIfFull">Stop collecting Trains <br>
				<input type="checkbox" id="receiveTrain">Handle incoming Trains<br>
				<input type="checkbox" id="sentTrain">Send Train
				&nbsp;Pick a Tour:
				<select id="trainMissionIN">'.$this->GetOptionsByTypeName("train").'</select> <br></td>
			<td><img src="'.$imagePath.'assets/NPC/Car_train/train_cargo/cargo_train_01_SW_icon.png" name="pictures" ></td>
			</tr>
			</table>
			<br>';
		// Ferry ================================================================================			
		echo  '<table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Ferry</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<td>
				<input type="checkbox" id="actionFerry">Collect/Supply Ferry<br><br></td>
			<td><img src="'.$imagePath.'assets/keys/key_ferry/key_ferry_icon.png" name="pictures" ></td>
			</tr>
			</table>
			<br>';
		// Ships ================================================================================	
		echo  '     <table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Cargo Ship</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<td>
				<input type="checkbox" id="NoShipIfFull">Stop collecting Ships<br>
				<input type="checkbox" id="receiveShip">Handle incoming Ships<br>
				<input type="checkbox" id="sentShip">Send Ships
				&nbsp;Pick a Tour:
				<select name="picture" id="shipMissionIN"  onChange="showimage()">'.$this->GetOptionsByTypeName("ship_contract").'</select> <br></td>
			<td width="100%"><img src="'.$imagePath.'assets/goods/goods_ships/ship_smallboat/smallboat_icon.png" name="pictures" ></td>
			</tr>
			</table>
			<br>'; 
		// Cruise Ship ================================================================================			
		echo  '  <table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Cruise Ship</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<td>
				<input type="checkbox" id="collectCruise">Handle incoming Cruise Ship<br>
				<input type="checkbox" id="sentCruise">Send Cruise Ship
				&nbsp;Pick a Tour:
				<select id="cruiseMissionIN">'.$this->GetOptionsByTypeName("cruise_contract").'</select> <br></td>
			<td width="100%"><img src="'.$imagePath.'assets/ships/ship_cruise/ship_cruise_B_icon.png" name="pictures" ></td>
			</tr>
			</table>
			
			
									Select the Cruiser you like to collect/supply:<br>';

		if(!isset($settings['collectCruiseIN'])) $settings['collectCruiseIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetObjects();
		foreach ($objects as $key=>$item)
		{
			if ((string)$item['className'] == "HarvestableShip")

			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectCruiseIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="sell1" size="10" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.sell1, this.form.sell2); sortSelect(this.form.sell2)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.sell2, this.form.sell1); sortSelect(this.form.sell1)" />
			</td>
			<td>
				<select name="sell2" size="10" multiple="multiple" id="collectCruiseIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
		<br>';
		// Truck ================================================================================
    echo '	<table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Truck Depot</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<td>
				<br><input type="checkbox" id="collectTruck">Handle incoming Trucks<br>
				<input type="checkbox" id="sentTruck">Send Trucks
				&nbsp;Pick a Tour:
				<select id="truckingContractIN">'.$this->GetTruckingContractByGoods("trucking_contract").'</select> <br>
				
				<br><input type="checkbox" id="clearTruck">Clear Trucks<br>
			<td width="100%"><img src="'.$imagePath.'Plugins/CV_Im-Export/helpers/trucking_truck_SW.png" name="pictures" ></td>
			</tr>
			</table>
			<br>
			
	    Select the Trucks you like to collect/supply:<br>';

		if(!isset($settings['collectTruckIN'])) $settings['collectTruckIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetDTObjects();
		foreach ($objects as $key=>$item)
		{
			if ((string)$item['className'] == "Truck")
			
			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectTruckIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
		$obj = $this->ld->GetObjectById($id);
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{		
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="selll3" size="7" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.selll3, this.form.selll4); sortSelect(this.form.selll4)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.selll4, this.form.selll3); sortSelect(this.form.selll3)" />
			</td>
			<td>
				<select name="selll4" size="7" multiple="multiple" id="collectTruckIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
		<br>';
		
echo  'Below here you have some more Information on your Trucks.<br>';
echo $this->GetTrucks();
		
		
		// Airline ================================================================================
		// ============= Cargo ======================================================================
	echo '	<br>
		    <table border="1" cellspacing="1" cellpadding="1" width="100%" bgcolor="#ff0066">
			<tr height="23">
			<td><h3>Airline</h3></td>
			</tr>
			</table>
			<table>
			<tr>
			<b>Options: Cargo</b>
			<td>
				<br><input type="checkbox" id="collectCargo">Handle incoming Planes<br>
				<input type="checkbox" id="sentCargo">Send Planes
				&nbsp;Pick a Tour:
				<select id="airplaneMissionCargoIN">'.$this->GetContractByTypeAndKeyword("airplane_contract", "cargo_plane_contract").'</select> <br>
				<input type="checkbox" id="clearCargo">Clear Airplanes</td>
			<td width="100%"><img src="'.$imagePath.'assets/airports/JetlinerB/plane_jetlinerB_icon.png" name="pictures" ></td>
			</tr>
			</table>
			<br>
			
	Select the Planes you like to collect/supply:<br>';

		if(!isset($settings['collectCargoIN'])) $settings['collectCargoIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetObjects();
		foreach ($objects as $key=>$item)
		{
			if (((string)$item['itemName'] == "sky_cargo_plane") ||
					((string)$item['itemName'] == "cloud_cargo_plane") ||
					((string)$item['itemName'] == "air_cargo_plane"))
			
			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectCargoIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="sell3" size="10" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.sell3, this.form.sell4); sortSelect(this.form.sell4)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.sell4, this.form.sell3); sortSelect(this.form.sell3)" />
			</td>
			<td>
				<select name="sell4" size="10" multiple="multiple" id="collectCargoIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
		<br>';
		
		// ============= Passenger ======================================================================
		echo '<hr>
			<table>
			<tr>
			<b>Options: Passenger</b>
			<td>
				<input type="checkbox" id="collectPassenger">Handle incoming Planes<br>
				<input type="checkbox" id="sentPassenger">Send Planes
				&nbsp;Pick a Tour:
				<select id="airplaneMissionPassengerIN">'.$this->GetContractByTypeAndKeyword("airplane_contract", "passenger_plane_contract").'</select> <br></td>
			<td width="100%"><img src="'.$imagePath.'assets/airports/JetlinerH/plane_jetlinerH_icon.png" name="pictures" ></td>
			</tr>
			</table>

			
	Select the Planes you like to collect/supply:<br>';

		if(!isset($settings['collectPassengerIN'])) $settings['collectPassengerIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetObjects();
		foreach ($objects as $key=>$item)
		{
			if (((string)$item['itemName'] == "cityville_passenger_plane") ||
					((string)$item['itemName'] == "econair_passenger_plane") ||
					((string)$item['itemName'] == "jetset_passenger_plane") ||
					((string)$item['itemName'] == "firstclass_passenger_plane") ||
					((string)$item['itemName'] == "privatejet_passenger_plane"))
			
			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectPassengerIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="sell5" size="10" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.sell5, this.form.sell6); sortSelect(this.form.sell6)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.sell6, this.form.sell5); sortSelect(this.form.sell5)" />
			</td>
			<td>
				<select name="sell6" size="10" multiple="multiple" id="collectPassengerIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
			<br>';
		
		// ============= Holiday ======================================================================
		echo '<hr>
			<table>
			<tr>
			<b>Options: Holiday</b>
			<td>
				<input type="checkbox" id="collectVacation">Handle incoming Planes<br>
				<input type="checkbox" id="sentVacation">Send Planes
				&nbsp;Pick a Tour:
				<select id="airplaneMissionVacationIN">'.$this->GetContractByTypeAndKeyword("airplane_contract", "vacation_plane_contract").'</select> <br></td>
			<td width="100%"><img src="'.$imagePath.'assets/airports/JetlinerVacation/plane_jetlinerVacation_icon.png" name="pictures" ></td>
			</tr>
			</table>

			
	Select the Planes you like to collect/supply:<br>';

		if(!isset($settings['collectVacationIN'])) $settings['collectVacationIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetObjects();
		foreach ($objects as $key=>$item)
		{
			if ((string)$item['itemName'] == "dreamline_plane")
			
			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectVacationIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="sell7" size="3" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.sell7, this.form.sell8); sortSelect(this.form.sell8)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.sell8, this.form.sell7); sortSelect(this.form.sell7)" />
			</td>
			<td>
				<select name="sell8" size="3" multiple="multiple" id="collectVacationIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
			<br>';
			
	   // ============= Private Jet ======================================================================
		echo '<hr>
			<table>
			<tr>
			<b>Options: Private Jet</b>
			<td>
				<input type="checkbox" id="collectPrivate">Handle incoming Planes<br>
				<input type="checkbox" id="sentPrivate">Send Planes
				&nbsp;Pick a Tour:
				<select id="airplaneMissionPrivateIN">'.$this->GetContractByTypeAndKeyword("airplane_contract", "private_plane_contract").'</select> <br></td>
			<td width="100%"><img src="'.$imagePath.'assets/airports/PrivateJetA/plane_privatejetA_icon.png" name="pictures" ></td>
			</tr>
			</table>

			
	Select the Planes you like to collect/supply:<br>';

		if(!isset($settings['collectPrivateIN'])) $settings['collectPrivateIN'] = array();
		$resNOT="";
		$resN = array();
		$resIN="";
		$resI = array();
		$objects = $this->ld->GetObjects();
		foreach ($objects as $key=>$item)
		{
			if (((string)$item['itemName'] == "skywing_jet") ||
			    ((string)$item['itemName'] == "time_pigeon_jet"))
			
			{
				$found = "N";
				if (in_array((string)$item['id'],$settings['collectPrivateIN'])) {$found = "Y";}
				if($found == "Y" )
				{ $resI[$item['id']] = (string)$item['itemName'];}
				else
				{ $resN[$item['id']] = (string)$item['itemName'];}
			}
		}
		natcasesort($resI);
		natcasesort($resN);
		foreach ($resI as $id=>$item)
		{
			$resIN .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		foreach ($resN as $id=>$item)
		{
			$resNOT .= '<option value="'.$id.'">'.$item." ($id)</option>";
		}
		echo  '<table class="table0">
			<th>Do NOT collect/supply</th><th></th><th>Do collect/supply</th></tr>
			<tr>
			<td>
				<select name="sell9" size="10" multiple="multiple">';
		echo $resNOT;
		echo '     </select>
			</td>
			<td align="center" valign="middle">
				<input type="button" value="--&gt;"onclick="moveOptions(this.form.sell9, this.form.sell10); sortSelect(this.form.sell10)" /><br />
				<input type="button" value="&lt;--"onclick="moveOptions(this.form.sell10, this.form.sell9); sortSelect(this.form.sell9)" />
			</td>
			<td>
				<select name="sell10" size="10" multiple="multiple" id="collectPrivateIN">';
		echo $resIN;
		
		
		echo '   </select>
			</td>
			</tr>
		</table>
			<br>';
		

		echo  '
			<div width="100%" align="center"><hr>
			<button id="btn_save" style="color:white;background-color:#13a89e;border-width:1px;border-style:solid; ">&nbsp;Save Settings&nbsp;</button>
			</div>';

		echo  '<hr>Below here you have some more Information on your Ships & Planes.<br>';
		echo  '<h2>Here the current Airline contracts</h2>
				&nbsp;&nbsp;<b>Cargo Airline</b><br> ';
		echo $this->GetPlanesCargo();
		echo  '<br>&nbsp;&nbsp;<b>Passenger Airline</b><br> ';
		echo $this->GetPlanesPassenger();
		echo  '<br>&nbsp;&nbsp;<b>Holiday Airline</b><br> ';
		echo $this->GetPlanesHoliday();
		echo  '<br>&nbsp;&nbsp;<b>Private Jet</b><br> ';
		echo $this->GetPlanesPrivate();
		echo  '<br><hr>
			<h2>Here the current Ship contracts</h2>
				&nbsp;&nbsp;<b>Cargo Ship</b><br> ';
		echo $this->GetShips();
		echo  '<br>&nbsp;&nbsp;<b>Cruise Ship</b><br> ';	            
		echo $this->GetShips1();	
		echo '    <br><h2>Posible Train Missions</h2><br>
						<table class="table1">
						<tr><td>Mission name:</td><td>Trip Time (Sec)</td><td>Train Storage (Goods)</td><td>Buy Price / goods (Coins)</td><td>Total Price (Coins)</td><td>Need Quest to unlock</td></tr>
						'.$this->GetOptionsByTypeName2("train").'
						</table>
						<br>';
		echo '  <h2>  Ship mission. (Work in progress.)</h2><br>
						<table class="table1">
						<tr><td>Mission name:</td><td>Trip Time</td><td>Ship Storage (Goods)</td><td>Buy Price / goods (Coins)</td><td>Total Price (Coins)</td><td>Need Quest to unlock</td></tr>
						'.$this->GetOptionsShip("ship_contract").'
						</table>        </form>';

	}

}

?>